import axios from "axios";

const getResult = async (id:number, type: string,name:string)=>{
    return new Promise((resolve, reject) => {
        axios.get('/api/project/getResultByProjectId',{
            params:{
                projectId:id,
                type
            },
            responseType: 'blob'
        }).then((response)=>{
            const content = response.data;
            const blob = new Blob([content]);
            if ('download' in document.createElement('a')) {
                // 非IE下载
                const elink = document.createElement('a');
                elink.download = name;
                elink.style.display = 'none';
                elink.href = URL.createObjectURL(blob);
                document.body.appendChild(elink);
                elink.click();
                // 释放URL对象
                URL.revokeObjectURL(elink.href);
                document.body.removeChild(elink);
            } else {
                // @ts-ignore
                navigator.msSaveBlob(blob, name)
            }
        })
    })

}

export default getResult;